package com.xiaoxie.config;

import com.xiaoxie.controller.JwtTokenAdminInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@Slf4j
@EnableWebMvc
public class CorsConfiguration implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info("开始处理跨域");
        registry.addMapping("/**")
                .allowedOrigins("*")  // 允许所有来源的跨域请求
                .allowedMethods("GET", "POST", "PUT", "DELETE")  // 允许的请求方法
                .allowedHeaders("*");  // 允许所有请求头
    }

        // 配置静态资源放行
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("放行静态资源" );
            registry.addResourceHandler("/static/**")
                    .addResourceLocations("classpath:/static/");

        }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("准备拦截器" );
        registry.addInterceptor(new JwtTokenAdminInterceptor())
                .addPathPatterns("/word/**");// 设置拦截的路径，这里假设 API 请求的路径是以 "/api" 开头
    }


}
